/*******************************************************************************
 * Copyright (c) 2008-2010 Cedric Vidal
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Cedric Vidal - original idea, initial contribution and API
 *******************************************************************************/

package org.trans4j.spring;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;

/**
 * Trans4j auto proxy creator that identifies mapper beans to instrument via a
 * list of annotations. By default, uses the {@link Mapper} annnotation.
 * 
 * @author <a href="mailto:c.vidal@proxiad.com">Cedric Vidal, ProxiAD Group</a>
 * @see AbstractTrans4jAutoProxyCreator
 * 
 */
public class AnnotationTrans4jAutoProxyCreator extends
		AbstractTrans4jAutoProxyCreator {

	public List<Class<? extends Annotation>> getAnnotations() {
		if(annotations == null) {
			annotations = new ArrayList<Class<? extends Annotation>>();
			annotations.add(Mapper.class);
		}
		return annotations;
	}

	public void setAnnotations(List<Class<? extends Annotation>> annotations) {
		this.annotations = annotations;
	}

	private List<Class<? extends Annotation>> annotations;

	protected boolean isMapper(Class<?> beanClass, String beanName) {
		for (Class<? extends Annotation> annotationClass : getAnnotations()) {
			Annotation annotation = beanClass.getAnnotation(annotationClass);
			if(annotation != null) {
				return true;
			}
		}
		return false;
	}

}
